package com.sofwin.controller;

import com.sofwin.Constants;
import com.sofwin.dto.ResourceDto;
import com.sofwin.pojo.SysResource;
import com.sofwin.pojo.SysUser;
import com.sofwin.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @packageName: com.sofwin.controller
 * @user: andyliu
 * @date: 2023/5/16 9:45
 * @email 115176513@qq.com
 * @description: TODO
 */
@Controller
@RequestMapping("index")
public class IndexController {
    @Autowired
    private RoleService roleService;
    @GetMapping
    public String index(HttpSession session, Model model){
        SysUser user = (SysUser)session.getAttribute(Constants.CURRENT_USER);
        // 根据角色ID查询该角色拥有的资源
        // ?
        // List ?
        List<ResourceDto> resources = roleService.queryResourcesByRoleId(user.getRoleId());
        model.addAttribute("resources",resources);
        return "index";
    }
}
